<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.Date" %>
<%@page import="java.text.SimpleDateFormat" %>
<%@taglib uri="/roomUtil"  prefix="roomUtil"%>
<%@taglib uri="/adminUtil"  prefix="adminUtil"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<br>
<style>
	#offDiv{
		display:none;
	}
	#onDiv{
		display:none;
	}
	#reserveInforDiv{
		display:none;
	}
</style>
<script type="text/javascript" src="/hotel/js/jquery.min.js"></script>
<script type="text/javascript" src="/hotel/js/timeUtil.js"></script>
<script type="text/javascript">
	function clearRoomInfor(){
		$('#roomId').val('')
		$('#price').text('')
		$('#pic').attr('src','')
		$('#addDate').text('')
		$('#zcomment').text('')
	}
	//更新房间信息
	function refreshRoomInfor(id){
		if(id!=null){
			$.get("/hotel/checkIn/roomInfor",{'id':id},function(str){
				//alert(str)
				var res=eval('(' +str + ')')
				if(res.code!=0){
					alert(res.message)
					return;
				}
				room=res.object
				$('#roomId').val(room.id)
				$('#price').text(room.price+'元/日(房型折扣:'+room.typeDiscount+'%,房间折扣:'+room.discount+'%)')
				$('#calcPrice').val(room.price)
				$('#pic').attr('src','/hotel/upload/'+room.pic)
				$('#addDate').text(room.addDate)
				$('#zcomment').text(room.zcomment)
			})
		}
	}
	//更新类型选择列表
	function refreshTypeList(){
		$('#typeId').empty()
		$('#room').empty()
		$.get("/hotel/checkIn/typeList",{},function(str){
			//alert(str)
			var res=eval('(' +str + ')')
			if(res.code!=0){
				alert(res.message)
				return;
			}
			types=res.object
			for(var i=0;i<types.length;i++){
				//alert(types[i].id+' '+types[i].name)
				$('#typeId').append('<option value='+types[i].id+'>'+types[i].name+'</option>')
			}
		})
	}
	
	//更新房间选择列表
	function refreshRoomList(id){
		$('#room').empty()
		$.get("/hotel/checkIn/freeRoomList",{'id':id},function(str){
			//alert(str)
			var res=eval('(' +str + ')')
			if(res.code!=0){
				alert(res.message)
				return;
			}
			rooms=res.object
			for(var i=0;i<rooms.length;i++){
				//alert(types[i].id+' '+types[i].name)
				$('#room').append('<option value='+rooms[i].id+'>'+rooms[i].floor+'F-'+rooms[i].name+'</option>')
			}
			//$('#room').val(rooms[0].id)
			if(rooms.length>0){//如果有符合条件的房间
				refreshRoomInfor(rooms[0].id)	//更新房间信息
			}
		})
	}
	//锁定某房间
	function lockRoom(id,code){
		$.post("/hotel/checkIn/lockRoom",{'id':id,'code':code},function(str){
			//alert(str)
			var res=eval('(' +str + ')')
			if(res.code!=0){
				alert(res.message)
				refreshTypeList()
				return;
			}
		})
	}
	//计算并展示价格
	function showPrice(){
		str1=$('#inTime').val();
		str2=$('#outTime').val();
		//算法有问题
		price=getDurDays(str1,str2)*$('#calcPrice').val()	//普通房价格计算法
		//price=getDurSeconds(str1,str2)/(24.0 *3600)*$('#calcPrice').val()		 //秒数/24.0/3600*price
		//price=Math.round(price)
		$('#cost').text(price+'元')
	}
	function submitInfor(){
		
	}
	$('#typeId').change(function(){
		clearRoomInfor()
		refreshRoomList($('#typeId').val())
	})
	$('#room').change(function(){
		refreshRoomInfor($('#room').val())
	})
	$('#lock').click(function(){
		if($('#lock').text()=='锁定该房间'){
			$('#lock').text('解锁该房间')
			lockRoom($('#roomId').val(),1)
		}else{
			$('#lock').text('锁定该房间')
			lockRoom($('#roomId').val(),0)
		}
	})
	$('#calc').click(function(){
		showPrice()
	})
	$('#sub').click(function(){
		data={'phone':$('#phone').val(),'idCardNo':$('#idCardNo').val(),'dateStr1':$('#inTime').val(),'dateStr2':$('#outTime').val(),
				'zcomment':$('#checkInComment').text(),'roomId':$('#roomId').val()}
		//alert(JSON.stringify(data))
		$.post("/hotel/checkIn/offlineCheck",data,function(str){
			//alert(str)
			var res=eval('(' +str + ')')
			if(res.code!=0){
				alert(res.message)
				//refreshTypeList()
				return;
			}else{
				window.location.href="/hotel/system/mainPage"
			}
		})
	})
	$("#offBut").click(function(){
		$('#onDiv').css('display','none')
		$('#offDiv').css('display','block')
	})
	
	
	
	
	refreshTypeList()
	
	
</script>
